package itsm.isperp.module.controller.map.baidu;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.app.AppUser;
import itsm.isperp.module.service.app.AppUserService;
import itsm.isperp.module.service.bpm.act.ActRuTaskService;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-4-11
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("map/baidu")
public class MapController {

	@RequestMapping("manage")
	public ModelAndView manage() {
		ModelAndView mv = new ModelAndView("map/baidu/manage");

		return mv;

	}
	
	@RequestMapping("ciSpreadManage")
	public ModelAndView ciSpreadManage() {
		ModelAndView mv = new ModelAndView("map/baidu/ciSpreadManage");
		return mv;
	}

	@RequestMapping("listUsers")
	@ResponseBody
	public List<AppUser> listUsers() {
		AppUserService appUserService = ContextHolder
				.getSpringBean("appUserService");
		JqGridRequest req = new JqGridRequest();
		req.setSelectColumns("id", "name", "fullname", "photo", "longitude",
				"latitude");

		req.isPageable(false);

		req.addFilterRule("longitude", JqGridFilterRuleOp.isnotnull, null);

		List<AppUser> list = appUserService.findAll(req);

		ActRuTaskService actRuTaskService = ContextHolder
				.getSpringBean("actRuTaskService");

		for (AppUser u : list) {
			u.setChannelId(actRuTaskService.getTaskCount(u.getUsername()));

		}

		return list;
	}

	@RequestMapping("listIncidents")
	@ResponseBody
	public List<AppUser> listIncidents() {

		return null;

	}

	@RequestMapping("listCis")
	@ResponseBody
	public List<Map<String,Object>> listCis() {
		JdbcTemplate jdbcTemplate = ContextHolder.getSpringBean("jdbcTemplate");
		String sql="select a.*,b.pv from conf_ci a left join v_conf_property_pv b on a.id=b.conf_ci_id where (b.pv like '%经度%')";
		return jdbcTemplate.queryForList(sql);
	}
}
